/*
* CourseStatisticsService.java
* Created on  2014-5-15 上午9:42
* 版本       修改时间          作者      修改内容
* V1.0.1    2014-5-15       gaoxinyu    初始版本
*
*/
package com.genghis.ptas.course.service.impl;

import com.genghis.core.page.entity.Page;
import com.genghis.core.page.entity.PageParameter;
import com.genghis.ptas.constant.DictConstant;
import com.genghis.ptas.course.dao.CourseStatisticsDao;
import com.genghis.ptas.course.entity.CourseInfo;
import com.genghis.ptas.course.service.CourseStatisticsService;
import com.genghis.ptas.statistic.entity.CourseStatistics;
import com.genghis.ptas.statistic.entity.Range;
import com.genghis.ptas.statistic.entity.Statistic;
import com.genghis.ptas.system.service.DictService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 类的描述信息
 *
 * @author fengxuanzhen
 * @version 1.0.1
 */
@Service("courseStatisticsService")
public class CourseStatisticsServiceImpl implements CourseStatisticsService {

    @Autowired
    private CourseStatisticsDao courseStatisticsDao;

    @Autowired
    private DictService dictService;

    @Override
    public int addCourseStatistics(CourseStatistics courseStatistics) {
        return courseStatisticsDao.addCourseStatistics(courseStatistics);
    }

    @Override
    public CourseStatistics findCourseStatisticsById(Integer id) {
        return courseStatisticsDao.findCourseStatisticsById(id);
    }

    @Override
    public CourseStatistics findCourseStatisticsByCourseId(Integer courseId) {
        return courseStatisticsDao.findCourseStatisticsByCourseId(courseId);
    }

    @Override
    public void editCourseStatistics(CourseStatistics courseStatistics) {
        courseStatisticsDao.editCourseStatistics(courseStatistics);
    }

    @Override
    public void delCourseStatistics(Integer courseId) {
        courseStatisticsDao.delCourseStatistics(courseId);
    }

    @Override
    public Page<CourseStatistics> findAllStatisticList(PageParameter pageParameter, CourseStatistics courseStatistics, Range range) {
        Page<CourseStatistics> courseStatisticsPage = courseStatisticsDao.findAllStatisticList(pageParameter, courseStatistics,range);
        for (CourseStatistics courseStatisticsTemp : courseStatisticsPage.getResultList()) {
            courseStatisticsTemp.setShowQuality(dictService.changeDictCodeToValue(courseStatisticsTemp.getQuality(), DictConstant.QUALITY));
        }
        return courseStatisticsPage;
    }

    @Override
    public void assessQuality(CourseInfo courseInfo) {
        CourseStatistics courseStatistics = findCourseStatisticsByCourseId(courseInfo.getId());
        courseStatistics.setQuality(courseInfo.getQuality());
        courseStatisticsDao.editCourseStatistics(courseStatistics);
    }

    @Override
    public void updateAverageScoreByCourseId(Integer courseId) {
        CourseStatistics courseStatistics = courseStatisticsDao.findNewsetAverageScoreByCourseId(courseId);
        courseStatisticsDao.editCourseStatistics(courseStatistics);
    }

    @Override
    public Page<Statistic> findUserStatisticList(PageParameter pageParameter, Statistic statistic,Range range) {
        return courseStatisticsDao.findUserStatisticList(pageParameter,statistic,range);
    }
}
